package com.school.fuyuan.business.service;

import com.school.fuyuan.business.mapper.PrivilegeMapper;
import com.school.fuyuan.business.model.po.Privilege;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zrhong
 * @version 1.0
 * @date 2019/3/26 22:26
 * @description
 */
@Service
public class PrivilegeService {
    private final PrivilegeMapper privilegeMapper;

    public PrivilegeService(PrivilegeMapper privilegeMapper) {
        this.privilegeMapper = privilegeMapper;
    }

    public List<Privilege> getPrivileges() {
        return privilegeMapper.getPrivileges(null);
    }

    public void addPrivilege(String privilegePath) {
        privilegeMapper.addPrivilege(privilegePath);
    }

    public void updatePrivilege(Privilege privilege) {
        privilegeMapper.updatePrivilege(privilege);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deletePrivilege(String privilegeId) {
        privilegeMapper.deletePrivilege(privilegeId);
        privilegeMapper.deleteRolePrivilege(privilegeId);

    }
}
